2617. Birthdays

 

If somebody in Summer Computer School (SCS) has a birthday, the celebration is arranged. Help organizers to find out how many times they must arrange the birthday parties during SCS.August.

 

Input. First number contains the amount of SCS – children, who celebrates their birthdays in August, then in the same line given the dates of their birthdays. The number of birthdays in SCS.August is no more than 300.

 

Output. Print the number of days with birthdays celebration.

 

Sample input

Sample output

6 1 2 5 2 2 20

4

 

 

SOLUTION

counting sort

 

Algorithm analysis

Note that we are only interested in birthdays for August (one month), that has 31 days. For each day from 1 to 31, calculate how many LKSH students were born on that day. And then count the number of days when LKSH students celebrate birthdays.

 

Algorithm realization

Birthdays can range from 1 to 31 inclusive (31 days in August). In the cell m[i] count the number of LKSH students whose birthday falls exactly on the day number i.

 

#define MAX 32

int m[MAX];

 

The main part of the program.

 

scanf("%d",&n);

memset(m,0,sizeof(m));

 

For each day count the number of LKSH students who have this day their birthday.

 

for(i = 0; i < n; i++)

{

  scanf("%d",&day);

  m[day]++;

}

 

In the variable res, count the number of days when the birthdays are celebrated. If m[i] is not zero, then there is at least one student whose birthday is August i.

 

for(res = i = 0; i < MAX; i++)

  if (m[i]) res++;

 

Print the number of holidays.

 

printf("%d\n",res);